import { App } from './app';
import Util from './util';
import { Page } from './page';

App.registerCrud({
	route: 'good',//路由名称
	url: $.config('apiUrl') + 'good',
	title: '商品&服务项目',//分页标题
	capable: {
		create: true
	},
	columns: [{
		dataField: 'name',
		caption: '商品名称'
	}, {
		dataField: 'code',
		caption: '商品编码',
		sortOrder:'asc'
		// sortIndex:'code',
		// sortingMethod:function(a,b){
		// 	return a<b
		// }
	}, {
		dataField: 'categoryId',
		caption: '商品分类'
	}, {
		dataField: 'price',
		caption: '商品价格'
	}, {
		dataField: 'serviceTime',
		caption: '服务时间'
	}, {
		dataField: 'projectTypeId',
		caption: '项目类型'
	}, {
		dataField: 'site.name',
		caption: '场地类型'
	}, {
		dataField: 'jobId',
		caption: '工种'//名称
	}, {
		dataField: 'applySex',
		caption: '适用性别',
		cellTemplate:function(e,d){
			let text = '';
			switch(d.data.applySex){
				case '':text = '未指定';break;
				case 1:text = '男';break;
				case 2:text = '女';break
			}
			$(e).text(text)
		}
	}, {
		dataField: 'shortName',
		caption: '商品简称'
	}, {
		dataField: 'plu',
		caption: '拼音助词码'
	}, {
		dataField: 'scanCode',
		caption: '条码'
	}, {
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/good/edit/{{id}}'//#/路由名称/edit/{{id}}
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));

			return true;
		},
		items: [{
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '商品名称' }//名称
		}, {
			dataField: 'code',
			validationRules: [{ type: "required" }],
			label: { text: '商品编码' },

		}, {
			dataField: "categoryId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'good-category?_no_page=1'),
				showClearButton: true,
				placeholder: "商品分类",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到商品分类数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '商品分类' }
		}, {
			dataField: "price",
			editorType: 'dxNumberBox',
			label: { text: '商品价格' }
		}, {
			dataField: "serviceTime",
			editorType: 'dxNumberBox',
			label: { text: '服务时间' }
		}, {
			dataField: "projectTypeId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'project-type?_no_page=1'),
				showClearButton: true,
				placeholder: "项目类型",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到项目类型数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '项目类型' }//名称
		}, {
			dataField: "siteId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'site?_no_page=1'),
				showClearButton: true,
				placeholder: "场地类型",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到场地类型数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '场地类型' }//名称
		}, {
			dataField: "jobId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'job?_no_page=1'),
				showClearButton: true,
				placeholder: "工种",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到工种数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '工种' }//名称
		}, {
			dataField: "applySex",
			label: { text: '适用性别' },//名称
			editorType: "dxSelectBox",
			editorOptions: {
				displayExpr: 'name',
				valueExpr: 'value',
				dataSource: [{ name: '男性', value: 1 }, { name: '女性', value: 2}, { name: '未指定', value: '' }]
			},
		}, {
			dataField: "shortName",
			label: { text: '商品简称' }//
		}, {
			dataField: "plu",
			label: { text: '拼音助词码' }//名称
		}, {
			dataField: "scanCode",
			label: { text: '条码' }//名称
		}]
	}
});

App.registerCrud({
	route: 'job',//路由名称
	url: $.config('apiUrl') + 'job',
	title: '工种',//分页标题
	capable: {
		create: true
	},
	columns: [{
		dataField: 'code',
		caption: '工种编号'
	}, {
		dataField: 'name',
		caption: '工种名称'
	}, {
		dataField: 'shiftsName',
		caption: '所选班次'
	},
	{
		dataField:'rolesName',
		caption:'权限'
	},
	//  {
	// 	dataField: 'shiftOrder',
	// 	caption: '轮班顺序'
	// }, {
	// 	dataField: 'workTime',
	// 	caption: '作息时间'
	// }, {
	// 	dataField: 'scrollTime',
	// 	caption: '滚动时间'
	// }, {
	// 	dataField: 'dateCount',
	// 	caption: '可预约天数'
	// }, {
	// 	dataField: 'createdAt',
	// 	caption: '创建时间'//名称
	// },
	{
		dataField: 'isShow',
		caption: '在前台显示',
		cellTemplate:function(ele,da){
			$(ele).text(da.data.isShow?'是':'否')
		}
	}, 
	// {
	// 	dataField: 'updatedAt',
	// 	caption: '修改时间'
	// },
	//	{
	//		dataField: 'updaterId',
	//		caption: '修改人'
	//	},
	{
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/job/edit/{{id}}'//#/路由名称/edit/{{id}}
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeDataShow:function(data){
			let arr = data.jobShifts.sort((a,b)=>a.sort-b.sort);
			if(arr.length){
				let ay = [];
				$(arr).each((index,item)=>{
					ay.push(item.shiftId)
				})
			 data.jobShifts	= ay
			}
			if(data.roles.length){
				let ar = [];
				$.each(data.roles,(index,item)=>{
					ar.push(item.id)
				})
				data.roles = ar;
			}else{
				data.roles = []
			}
			return data 
		},
		beforeDataSubmit:function(data){
			if(data.jobShifts.length){
				let ar =[];
				$(data.jobShifts).each((index,item)=>{
					ar.push({
						shiftId:item,
						sort:index
					})
				})
				data.jobShifts = ar
			}
			if(data.roles.length){
				let arr = [];
				$.each(data.roles,(index,item)=>{
					arr.push({id:item})
				})
				data.roles = arr
			}
			data.isShow = data.isShow?1:0;
			return data
		},
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));
			return true;
		},
		items: [{
			dataField: "code",
			validationRules: [{ type: "required" }],
			label: { text: '工种编号' }//名称
		}, {
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '工种名称' }//名称
		},
		//  {
		// 	dataField: "jobShifts",
		// 	name:'jobShiftsshow',
		// 	validationRules: [{ type: "required" }],
		// 	editorType: 'dxTagBox',
		// 	display:false,
		// 	editorOptions: {
		// 		deferRendering: false,
		// 		dataSource: Util.crudStore($.config('apiUrl') + 'shift?_no_page=1'),
		// 		showClearButton: true,
		// 		placeholder: "所选班次",
		// 		searchEnabled: true,
		// 		valueExpr: 'id',
		// 		displayExpr:'name',
		// 		noDataText: '没有请求到所选班次数据'
		// 	},
		// 	label: { text: '所选班次' }//名称
		// }, 
		{
			dataField: "jobShifts",
			name:'jobShiftshidden',
			editorType: 'dxTagBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'shift?_no_page=1'),
				showClearButton: true,
				placeholder: "所选班次",
				searchEnabled: true,
				valueExpr: 'id',
				displayExpr:'name',
				noDataText: '没有请求到所选班次数据'
			},
			label: { text: '所选班次' }//名称
		}, {
			dataField:'isShow',
			label:{text:'在前台显示'},
			editorType:'dxCheckBox',
			editorOptions:{
				value:false,
				// onValueChanged:function(e){
				// 	let value = e.value;
				// 	console.log($('#form').dxForm('instance').getEditor('jobShiftshidden'))
				// 	if(value){
				// 	$('#form').dxForm('instance').getEditor('jobShiftshidden').option('display',false)
				// 	$('#form').dxForm('instance').getEditor('jobShiftsshow').option('display',true)
				// 	}else{
				// 		$('#form').dxForm('instance').getEditor('jobShiftshidden').option('display',true)
				// 		$('#form').dxForm('instance').getEditor('jobShiftsshow').option('display',false)	
				// 	}
				// }
			}
		},{
			dataField: "shiftOrder",
			label: { text: '轮班顺序' }//名称
		}, {
			dataField: "workTime",
			editorType: 'dxDateBox',
			label: { text: '作息时间' }
		}, {
			dataField: "scrollTime",
			label: { text: '滚动时间' }
		}, {
			dataField: "dateCount",
			editorType: 'dxNumberBox',
			label: { text: '可预约天数' }
		}, {
			dataField: 'roles',
			label: { text: '权限' },
			editorType:'dxTagBox',
			editorOptions:{
				dataSource:Util.crudStore($.config('apiUrl') + 'role?_no_page=1'),
				displayExpr:'name',
				valueExpr:'id',
				showClearButton: true,
				placeholder: "权限选择",
				deferRendering: false
			}
		}
		]
	}
});

App.registerCrud({
	route: 'shift',//路由名称
	url: $.config('apiUrl') + 'shift',
	title: '班次',//分页标题
	capable: {
		create: true
	},
	columns: [{
		dataField: 'code',
		caption: '班次编号'
	}, {
		dataField: 'name',
		caption: '班次名称'
	}, {
		dataField: 'startAt',
		caption: '开始时间',
		cellTemplate: function(c, data) {
			c.text(moment(data.value).format("HH:mm"));
		}
	}, {
		dataField: 'closeAt',
		caption: '结束时间',
		cellTemplate: function (c, data) {
			c.text(moment(data.value).format("HH:mm"));
		}
	}, {
		dataField: 'minCount',
		caption: '最小人数'
	}, {
		dataField: 'maxCount',
		caption: '最大人数'
	}, {
		dataField: 'creatorId',
		caption: '创建人'//名称
	}, {
		dataField: 'createdAt',
		caption: '创建时间'
	}, {
		dataField: 'updaterId',
		caption: '修改人'
	}, {
		dataField: 'updatedAt',
		caption: '修改时间'
	}, {
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/shift/edit/{{id}}'//#/路由名称/edit/{{id}}
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));

			return true;
		},
		items: [{
			dataField: "code",
			validationRules: [{ type: "required" }],
			label: { text: '班次编号' }//名称
		}, {
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '班次名称' }//名称
		}, {
			dataField: "startAt",
			validationRules: [{ type: "required" }],
			editorType: 'dxDateBox',
			editorOptions: {
				type: 'time',
				displayFormat:'HH:mm:ss'
			},
			label: { text: '开始时间' }//名称
		}, {
			dataField: "closeAt",
			validationRules: [{ type: "required" }],
			editorType: 'dxDateBox',
			editorOptions: {
				type: 'time',
				displayFormat:'HH:mm:ss'
			},
			label: { text: '结束时间' }//名称
		}, {
			dataField: "minCount",
			editorType: 'dxNumberBox',
			label: { text: '最小人数' }//名称
		}, {
			dataField: "maxCount",
			editorType: 'dxNumberBox',
			label: { text: '最大人数' }//名称
		}
			//		,{
			//			dataField: "creatorId",
			//			label: { text: '创建人' }//名称
			//		},{
			//			dataField: "createdAt",
			//			editorType: 'dxDateBox',
			//			label: { text: '创建时间' }//名称
			//		},{
			//			dataField: 'updaterId',
			//			label: { text: '修改人' },
			//			
			//		}, {
			//			dataField: "updatedAt",
			//			editorType: 'dxDateBox',
			//			label: { text: '修改时间' },
			//		}
		]
	}
});

let postForm = function(url,data){
		Util.postForm(url,data)
			.then(res=>{
				if(res.data === 'success'){
					new DevExpress.ui.notify({message:'操作成功'},'success',1500);
					App.crudGridInstance().option('dataSource').load();
					$('#popups').dxPopup('instance').option('visible',false)
				}else{
					new DevExpress.ui.notify({message:'操作失败:'+res.errmsg},'warning',1500)
				}
			})
	};
let once_employee = false;
let dialogshow =function(id,type){
		$('#popups').html('');
		let options ={};
		let html = '<div class="leavebox" style="padding-bottom:10px"></div><div class="leavebutton"></div>';
		let methods = function(){	
					// DevExpress.ui.dialog.confirm('请确认操作','提示').done(result=>{
					// 	if(result){
							let dialogform = $('#popups').dxPopup('instance').content().find('.leavebox')
							if(type){
								dialogform = dialogform.dxForm('instance').option('formData')	
								for(let item in dialogform){
									dialogform[item] = new Date(dialogform[item]).getTime()
								};
								if(dialogform.start>dialogform.end){
									return new DevExpress.ui.dialog.alert('结束时间应大于或等于开始时间')
								}else{
									dialogform.employeeId = id;
									postForm($.config('apiUrl')+'employee/leave',dialogform)
								}
								}
							else{
								dialogform = dialogform.dxDataGrid('instance').getSelectedRowsData();
								if(dialogform.length){
									let arr = [];$(dialogform).each((index,item)=>{arr.push(item.id)})
									postForm($.config('apiUrl')+'employee/leave/cancel',arr)
								}else{
									new DevExpress.ui.dialog.alert('请先选择要取消的请假')
								}
							};
						// }
					// })
				}
		let formbutton = function(el){
			el.find('.leavebutton').dxToolbar({
						items:[{
							location:'after',
							widget:'dxButton',
							options:{
								type:'success',
								text:'提交',
								onClick:methods
							}
						},{
							location:'after',
							widget:'dxButton',
							options:{
								type:'success',
								text:'取消',
								onClick:function(){
									$('#popups').dxPopup('instance').option('visible',false)
								}
							}
						}]
					})
		};
		if(type){
			let now  = moment().add(1,'days');
			console.log(now)
			options = {
				title:'请假',
				width:'30%',
				visible:true,
				height:'auto',
				contentTemplate:function(ele){
					$(ele).append(html);
					$(ele).find('.leavebox').dxForm({
						formData:{start:new Date(),end:new Date()},
						colCount:1,
						items:[{
							label:{text:'开始时间'},
							dataField:'start',
							validationRules:[{type:'required'}],
							editorType:'dxDateBox',
							eidtorOptions:{
								value:now,
								type:'date',
								displayFormat: 'yyyy-MM-dd',
								dateSerializationFormat: "yyyy-MM-dd",
								}
							},{
							label:{text:'结束时间'},
							dataField:'end',
							validationRules:[{type:'required'}],
							editorType:'dxDateBox',
							eidtorOptions:{
								value:now,
								type:'date',
								displayFormat: 'yyyy-MM-dd',
								dateSerializationFormat: "yyyy-MM-dd",
							}
						}]
					});
					formbutton($(ele))
				}
			}
		}else{
			options = {
				title:'取消请假',
				width:'40%',
				visible:true,
				height:'auto',
				contentTemplate:function(ele){
					$(ele).append(html);
					$.get($.config('apiUrl')+'employee/leave/list/'+id).then(res=>{
						$(res.data).each((index,item)=>{
							item.end = moment(item.end).format('YYYY-MM-DD');
							item.start = moment(item.start).format('YYYY-MM-DD')
						})
					$(ele).find('.leavebox').dxDataGrid({
						dataSource:res.data||[],
						allowColumnResizing: true,
						selection: {
							mode: "multiple",
							showCheckBoxesMode: 'always',
							selectAllMode: 'page'
						},
						remoteOperations: true,
						paging: {
							pageSize: 10,
							pageIndex: 0
						},
						columns:[{
							caption:'开始时间',
							dataField:'start'
						},{
							caption:'结束时间',
							dataField:'end'
						}]
					})
				})
					formbutton($(ele))
			}
		}
	}
	$('#popups').dxPopup(options);
}

let  showSkill = function(data){
	$('#popups').html()
	let leaveEle = $('#popups').dxPopup({
		visible:true,
		title:'批量设置员工技能',
		width:'60%',
		height:'auto',
		contentTemplate:function(e){
			let html = '<div class="leavebox" style="margin-bottom:10px"></div><div class="leavebutton"></div>';
			$(e).append(html)
			let selection = []
			$(e).find('.leavebox').dxTagBox({
				dataSource:Util.crudStore($.config('apiUrl') + 'good?_no_page=1'),
				deferRendering:true,
                valueExpr: 'id',
                displayExpr: 'name',
                placeholder:'请选择员工技能',
                onValueChanged:function(e){
                	selection = e.value;
                }
			})

	$(e).find('.leavebutton').dxToolbar({
				items:[{
					location:'after',
					widget:'dxButton',
					options:{
						type:'success',
						text:'提交',
						onClick:function(){
							let form = {
								employees:[],
								goods:selection,
							}
							data.forEach(item=>{
								form.employees.push(item.id)
							})
							postForm($.config('apiUrl')+"employee/batch-assign-good",form)
						}
					}
				},{
					location:'after',
					widget:'dxButton',
					options:{
						type:'success',
						text:'取消',
						onClick:function(){
							$('#popups').dxPopup('instance').option('visible',false)
						}
					}
				}]
			})
		}
	})
}

App.registerCrud({
	route: 'employee',//路由名称
	url: $.config('apiUrl') + 'employee',
	title: '员工档案',//分页标题
	capable: {
		create: true
	},
	toolbar:{
		items:[
		'create'
		,{
		widget:'dxButton',
		location:'before',
		options:{
			text:'批量设置员工技能',
			onClick:function(){
			let data =App.crudGridInstance().getSelectedRowsData();
			if(data.length===0){return new DevExpress.ui.dialog.alert('请选择员工')}
			showSkill(data)
			}
		}
	}]
	},
	columns: [{
		dataField: 'code',
		caption: '员工编号',
		sortOrder:'asc'
	}, {
		dataField: 'name',
		caption: '员工名称'
	}, {
		dataField: 'sex',
		caption: '性别',
		cellTemplate:function(e,d){
			let sex = '未设置';
			if(d.value === 1){
				sex = '男'
			};
			if(d.value === 2){
				sex = '女'
			};
			$(e).text(sex)
		}
	}, {
		dataField: 'jobId',
		caption: '工种',
		cellTemplate:function(e,d){
			$(e).text(d.data.job.code+'-'+d.data.job.name)
		}
	}, {
		dataField: 'laborRelationId',
		caption: '劳务关系',
		cellTemplate:function(e,d){
			$(e).text(d.data.laborRelation.name)
		}
	}, {
		dataField: 'isWork',
		caption: '是否在职',
		cellTemplate:function(e,d){
			$(e).text(d.value?'是':'否')
		}
	}, {
		dataField: 'goodsName',
		caption: '员工技能'

	}, {
		dataField: 'password',
		caption: '员工密码'
	}, {
		dataField: 'cardId',
		caption: '卡ID'//名称
	}, {
		dataField: 'shopCode',
		caption: '门店号'
	},{
		dataField:'id',
		caption:'请假管理',
		cellTemplate(c,d){
		let html = '<span class="userManage"><a class="leave">请假</a><b>/</b><a class="cancelleave" title="取消请假">取消请假</a></span>'
		$(c).html(html);
		let id = d.data.id;
			$(c).find('a.leave').click(function(e){
				dialogshow(id,true)
			})
			$(c).find('a.cancelleave').click(function(e){
				dialogshow(id,false)
			})
		}
	}, {
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/employee/edit/{{id}}'
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeDataShow(data){
			once_employee = false
			if(data.goods.length){
				let arr = []
			$.each(data.goods,(index,item)=>{
				arr.push(item.id)
			});
			data.goods = arr
			}
			return data
		},
		beforeDataSubmit(data){
			if(data.goods){
				let arr = [];
				$.each(data.goods,(index,item)=>{
				arr.push({id:item})
			});
				data.goods = arr
			}
			return data
		},
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));

			return true;
		},
		items: [{
			dataField: "code",
			validationRules: [{ type: "required" }],
			label: { text: '员工编号' }//名称
		}, {
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '员工名称' }//名称
		}, {
			dataField: "sex",
			validationRules: [{ type: "required" }],
			label: { text: '性别' },//名称
			editorType: "dxSelectBox",
			editorOptions: {
				displayExpr: 'name',
				valueExpr: 'value',
				dataSource: [{ name: '男性', value: 1 }, { name: '女性', value: 2 }, { name: '未指定', value: '' }]
			},
		}, {
			dataField: "jobId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'job?_no_page=1'),
				showClearButton: true,
				placeholder: "工种",
				searchEnabled: true,
				valueExpr: 'id',
				displayExpr:'name',
				noDataText: '没有请求到工种数据',
				onValueChanged:function(e){
					let value = e.value;
					let instance = $('select[name="goods"]').parents('.dx-tagbox').dxTagBox('instance');
					$.get($.config('apiUrl') + 'good?_no_page=1').then(res=>{
						let data = res.data.filter(item=>item.jobId ==value)
						instance.option('dataSource',data);
					if(once_employee){App.getFormInstance().option('formData.goods',[])}
						once_employee = true;
					})
				}
			},
			label: { text: '工种' }//名称
		}, {
			dataField: "laborRelationId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'labor-relation?_no_page=1'),
				showClearButton: true,
				placeholder: "劳务关系",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到劳务关系数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '劳务关系' }//名称
		}, {
			dataField: "isWork",
			validationRules: [{ type: "required" }],
			editorType:'dxSelectBox',
			editorOptions:{
				valueExpr:'value',
				displayExpr:'name',
				dataSource:[{name:'是',value:1},{name:'否',value:0}],
				value:0
			},
			label: { text: '是否在职' }//名称
		}, {
			dataField: "goods",
			label: { text: '员工技能' },
			editorType:'dxTagBox',
			editorOptions:{
				showSelectionControls:true,
				deferRendering: false,
                dataSource:[],
                searchEnabled: true,
                valueExpr: 'id',
                displayExpr: 'name',
			}
		}, {
			dataField: 'password',
			validationRules: [{ type: "required" }],
			label: { text: '员工密码' },

		}, {
			dataField: "cardId",
			label: { text: '卡ID' },

		}, {
			dataField: "shopCode",
			validationRules: [{ type: "required" }],
			editorType: 'dxNumberBox',
			label: { text: '门店号' }

		}]
	}
});

App.registerCrud({
	route: 'room',//路由名称
	url: $.config('apiUrl') + 'room',
	title: '场地管理',//分页标题
	capable: {
		create: true
	},
	columns: [{
		dataField: 'number',
		caption: '编号',
		sortOrder:'asc'
	}, {
		dataField: 'name',
		caption: '场地名称'
	}, {
		dataField: 'site.name',
		caption: '场地类型'
	}, {
		dataField: 'max',
		caption: '容纳人数'
	}, {
		dataField: 'remark',
		caption: '备注'//名称
	}, {
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/room/edit/{{id}}'//#/路由名称/edit/{{id}}
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));

			return true;
		},
		items: [{
			dataField: "number",
			validationRules: [{ type: "required" }],
			label: { text: '编号' }//名称
		}, {
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '场地名称' }//名称
		}, {
			dataField: "siteId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'site?_no_page=1'),
				showClearButton: true,
				placeholder: "场地类型",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到场地类型数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '场地类型' }//名称
		},{
			dataField: "roomStatusId",
			validationRules: [{ type: "required" }],
			editorType: 'dxSelectBox',
			editorOptions: {
				deferRendering: false,
				dataSource: Util.crudStore($.config('apiUrl') + 'room-type?_no_page=1'),
				showClearButton: true,
				placeholder: "请选择房间状态",
				searchEnabled: true,
				valueExpr: 'id',
				noDataText: '没有请求到房间状态数据',
				itemTemplate: function (data, index, $el) {
					if (data) {
						$("<span>" + data.name + "</span>").appendTo($el);
					}
				},
				displayExpr: function (data) {
					return data ? data.name : "";
				}
			},
			label: { text: '房间状态' }//名称
		}, {
			dataField: "max",
			validationRules: [{ type: "required" }],
			editorType: 'dxNumberBox',
			label: { text: '容纳人数' }//名称
		}, {
			dataField: 'remark',
			label: { text: '备注' },

		}]
	}
});

App.registerCrud({
	route: 'boahandcardrd',//路由名称
	url: $.config('apiUrl') + 'handcard',
	title: '手牌管理',//分页标题
	capable: {
		create: true
	},
	columns: [{
		dataField: 'number',
		caption: '编号'
	}, {
		dataField: 'name',
		caption: '名称'
	}, {
		dataField: 'cardId',
		caption: '卡ID'
	}, {
		dataField: 'price',
		caption: '价格'
	}, {
		dataField: 'kidPrice',
		caption: '儿童价格'//名称
	}, {
		dataField: 'coord',
		caption: '屏幕显示坐标'
	}, {
		dataField: 'leastConsume',
		caption: '最底消费'
	}, {
		minWidth: 120,
		caption: '操作',
		buttons: [{
			title: '编辑',
			url: '#/boahandcardrd/edit/{{id}}'//#/路由名称/edit/{{id}}
		}]
	}],
	form: {
		readOnly: false,
		showColonAfterLabel: true,
		showValidationSummary: false,
		colCount: 1,
		beforeSubmit: function (form, id) {
			form.option('formData', Object.assign({ type: 'admin' }, form.option('formData')));

			return true;
		},
		items: [{
			dataField: "number",
			validationRules: [{ type: "required" }],
			label: { text: '编号' }//名称
		}, {
			dataField: "name",
			validationRules: [{ type: "required" }],
			label: { text: '名称' }//名称
		}, {
			dataField: "cardId",
			label: { text: '卡ID' }//名称
		}, {
			dataField: "price",
			editorType: 'dxNumberBox',
			label: { text: '价格' }//名称
		}, {
			dataField: 'kidPrice',
			editorType: 'dxNumberBox',
			label: { text: '儿童价格' },

		}, {
			dataField: "coord",
			editorType: 'dxNumberBox',
			label: { text: '屏幕显示坐标' },

		}, {
			dataField: "leastConsume",
			editorType: 'dxNumberBox',
			label: { text: '最底消费' }

		}]
	}
});